let token = getToken();
let user = JSON.parse(window.localStorage.getItem("userInfo"));
if (user) {
  let sietId;
  $("#payMethod").click(function () {
    let payList = [];
    var res = playGet(`/v1/api/blance/site/${user.id}`, "", "", token);
    if (res.code == 200) {
      res.data.forEach((item) => {
        if (item.payName && item.id) {
          let objs = {
            value: item.id,
            text: item.payName,
          };
          payList.push(objs);
        }
      });
      var picker = new mui.PopPicker();
      picker.setData(payList);
      picker.show(function (selectItems) {
        console.log(selectItems[0].text); //智子
        console.log(selectItems[0].value); //zz
        $("#payMethod").val(selectItems[0].text);
        sietId = selectItems[0].value;
      });
    } else {
      mui.alert(res.msg);
    }
  });

  // 回显已存在的用户信息
  $("#draw").click(function () {
    if (!$("#money").val()) {
      mui.alert("请输入金额");
      return false;
    }
    if (!sietId) {
      mui.alert("请收款方式");
      return false;
    }
    if ($("#money").val() % 100 > 0) {
      mui.alert("请输入100的倍数");
      return false;
    }
    var jon = {};
    jon["money"] = $("#money").val();
    jon["sietId"] = sietId;
    var res = playPost(`/v1/api/apply`, jon, "", token);
    if (res.code == 200) {
      mui.alert("提现成功");
      setTimeout(() => {
        location.href = "memberCenter.html";
      }, 1000);
    } else {
      mui.alert(res.msg);
    }
  });
} else {
  mui.alert("您还未登录，请先登录");
}
